<?php
namespace app\services;
 use Firebase\JWT\JWT;
 use Firebase\JWT\Key;
use Symfony\Component\VarDumper\VarDumper;
class JwtService{
    public function getToken($user){
        $key="dacongda";//自定义key值
        $payload=array(
            "iss"=>'',//签发者
            "aud"=>"",//接收者
            "iat"=>time(),//初始时间
            "nbf"=>time()+60*60*24*7,//过期时间为7天
            "user"=>$user,//前端页面传user
        );
        $jwt=JWT::encode($payload,$key,'HS256');
        return $jwt;
    }
    public function checkToken($token){
        $key="dacongda";//自定义key值
        $decoded=JWT::decode($token,new Key($key,'HS256'));
        return $decoded;
    }
}